win10查看文件的前n行和后n行 您所在的位置:网站首页 cat 查看前100行 win10查看文件的前n行和后n行

win10查看文件的前n行和后n行

2024-03-15 11:27| 来源: 网络整理| 查看: 265

    在Window10的PowerShell里,使用 type XXX|Select -First n 表示查找XXX文件的前n条记录,而 type XXX|Select -Last n 表示查找XXX文件的最后n条记录。这里以FileList.txt文件为例,进行说明。

1、创建FileList.txt文件

//createFileList.bat

REM @echo off @echo off set name=FileList.txt set time=hello_ for /l %%i in (1,1,100) do ( echo %time%%%i >>%name% )

    双击createFileList.bat得到的FileList.txt,其文件内容如下: //FileList.txt

hello_1 hello_2 hello_3 hello_4 hello_5 hello_6 hello_7 hello_8 hello_9 hello_10 hello_11 hello_12 hello_13 hello_14 hello_15 hello_16 hello_17 hello_18 hello_19 hello_20 hello_21 hello_22 hello_23 hello_24 hello_25 hello_26 hello_27 hello_28 hello_29 hello_30 hello_31 hello_32 hello_33 hello_34 hello_35 hello_36 hello_37 hello_38 hello_39 hello_40 hello_41 hello_42 hello_43 hello_44 hello_45 hello_46 hello_47 hello_48 hello_49 hello_50 hello_51 hello_52 hello_53 hello_54 hello_55 hello_56 hello_57 hello_58 hello_59 hello_60 hello_61 hello_62 hello_63 hello_64 hello_65 hello_66 hello_67 hello_68 hello_69 hello_70 hello_71 hello_72 hello_73 hello_74 hello_75 hello_76 hello_77 hello_78 hello_79 hello_80 hello_81 hello_82 hello_83 hello_84 hello_85 hello_86 hello_87 hello_88 hello_89 hello_90 hello_91 hello_92 hello_93 hello_94 hello_95 hello_96 hello_97 hello_98 hello_99 hello_100 2、统计的文件的总行数

    在Win10的黑框框里,切换到cmd模式,依次输入如下命令:

cmd find /V "" /C FileList.txt

    得到FileList.txt的总行数为100行。     如图(1)所示:

图(1) 在cmd模式下,查看文件的总行数 3、查看文件的前10行

    查看FileList.txt文件的前10行,需要黑框框切换到powershell模式,依次输入如下命令:

powershell type FileList.txt|Select -First 10

如图(2)所示:

图(2)在powershell模式下,查看FileList.txt的前10行 4、查看文件的最后10行

    查看FileList.txt文件的最后10行,需要黑框框切换到powershell模式,依次输入如下命令:

powershell type FileList.txt|Select -Last 10

    如图(3)所示:

图(3) 在powershell模式下,查看FileList.txt文件的最后10行


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有